package com.duckygo.towerdefense.game.scenes;

import javax.microedition.khronos.opengles.GL10;

import com.duckygo.towerdefense.R;
import com.duckygo.towerdefense.game.TextureManager;
import com.duckygo.towerdefense.game.sprites.IsometricLayoutSprite;
import com.duckygo.towerdefense.game.sprites.Sprite;
import com.duckygo.towerdefense.game.sprites.Sprite2D;
import com.duckygo.towerdefense.game.sprites.Terrain2DSprite;
import com.duckygo.towerdefense.game.sprites.Terrain3DSprite;
import com.duckygo.towerdefense.game.sprites.Tower;
import com.duckygo.towerdefense.game.sprites.Unit;
import com.duckygo.towerdefense.game.sprites.Viking;

import android.content.Context;
import android.util.Log;

public class TowerDefenseScene extends SceneManager {
	
	public static final int TOWER_TEX = 1;
	
	public static final int TERRAIN_TEX = 0;

	public static final int VIKING_TEX = 2;

	public static final int HEALTH_TEX = 3;
	
	public static final int FIREBALL_TEX = 4;
	
	public static final int EXPLOSION_TEX = 5;
	
	
	public static Terrain2DSprite terrain;

	public static Sprite layout;
	
	@Override
	public void register(GL10 gl, Context context) {
		super.register(gl, context);
		
		Log.w("TowerDefenseScene", "Registering scene");
		
		TextureManager.loadTexture(gl, context, R.drawable.groundtiles, TERRAIN_TEX);
		TextureManager.loadTexture(gl, context, R.drawable.tower, TOWER_TEX);
		TextureManager.loadTexture(gl, context, R.drawable.viking, VIKING_TEX);
		TextureManager.loadTexture(gl, context, R.drawable.health, HEALTH_TEX);
		TextureManager.loadTexture(gl, context, R.drawable.fireball, FIREBALL_TEX);
		TextureManager.loadTexture(gl, context, R.drawable.explosion, EXPLOSION_TEX);
		
		root.children.removeAllElements();
		
		terrain = new Terrain2DSprite(context.getResources().getString(R.string.level1_data));
		layout = new IsometricLayoutSprite();
		root.addChild(terrain);
		root.addChild(layout);
		
		for (int i = 0; i < 10; i++) {
			Tower tower = new Tower();
			tower.x = (float) (Math.random() * WIDTH);
			tower.y = (float) (Math.random() * HEIGHT);
			layout.addChild(tower);
		}
		
		for (int i = 0; i < 10; i++) {
			Viking viking = new Viking();
			viking.x = 0;//(float) (Math.random() * WIDTH);
			viking.y = -i * 30;//(float) (Math.random() * HEIGHT);
			layout.addChild(viking);
		}

	}
	
	@Override
	public void update(long time) {
		super.update(time);
//		sprite.scaleX = (float) Math.random() + 1;
//		sprite.scaleY = (float) Math.random() + 1;
	}
	
}
